package com.iwhalecloud.bss.kite.cucc.web.controller.attr;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.IInstallationAddressService;
import com.iwhalecloud.bss.kite.cucc.client.dto.attr.*;
import com.iwhalecloud.bss.kite.cucc.client.vo.attr.BuildingInfoVo;
import com.iwhalecloud.bss.kite.cucc.client.vo.attr.CircuitResourceInfoVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.attr.StandardAddressVO;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.ztesoft.bss.common.exception.BssException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname InstallationAddressController
 * @Description 装机地址控件涉及接口
 * @Author zhang.song
 * @Date 2021-02-24 12:02
 */
@Api(tags = { "/installationAddress - 装机地址" })
@RestController
@RequestMapping("/installationAddress")
public class InstallationAddressController {

    @Autowired
    private IInstallationAddressService installationAddressService;

    @ApiOperation(value = "标准地址查询", notes = "标准地址查询")
    @PostMapping("/queryStandardAddress")
    public DataResult<StandardAddressVO> queryStandardAddress(@RequestBody StdAddrQryDTO stdAddrQryDTO) {
        if(KiteStringUtils.isEmpty(stdAddrQryDTO.getAddrKeyword())) {
            BssException.throwOut("", "", "地址查询关键字不能为空");
        }

        String custId = KiteWebContext.getContext().getCustId();
        stdAddrQryDTO.setCustId(custId);
        StandardAddressVO standardAddressVO = installationAddressService.queryStandardAddress(stdAddrQryDTO);
        return ErrorConsts.SUCCESS.getResult(standardAddressVO);
    }

    @ApiOperation(value = "双线资源核查接口数据", notes = "双线资源核查接口数据")
    @PostMapping("/duCirResCheck")
    public DataResult<CircuitResourceInfoVO> duCirResCheck(
            @RequestBody PduCirResDTO pduCirResDTO) {
        String custId = KiteWebContext.getContext().getCustId();
        pduCirResDTO.setCustId(custId);
        CircuitResourceInfoVO circuitResourceInfoVO = installationAddressService.duCirResCheck(pduCirResDTO);
        return ErrorConsts.SUCCESS.getResult(circuitResourceInfoVO);
    }

    /**
     * 3.3.楼宇信息查询服务(使用地址ID)
     */
    @ApiOperation(value = "3.3.楼宇信息查询服务(使用地址ID)", notes = "3.3.楼宇信息查询服务(使用地址ID)")
    @PostMapping("/queryBuilding")
    public DataResult<BuildingInfoVo> queryBuilding(@RequestBody BuildingInquiryDTO buildingInquiryDTO) {
        return ErrorConsts.SUCCESS.getResult(installationAddressService.queryBuilding(buildingInquiryDTO));
    }

    /**
     * 资源核查接口
     */
    @ApiOperation(value = "资源核查接口", notes = "资源核查接口")
    @PostMapping("/resourPrejudgement")
    public DataResult<Object> resourPrejudgement(@RequestBody ResPreQryDTO resPreQryDTO) {
        return ErrorConsts.SUCCESS.getResult(installationAddressService.resourPrejudgement(resPreQryDTO));
    }
}
